package cn.gzsxt.utils;

import java.util.List;
import java.util.Map;

/**
 * 分页对象
 * @author ranger
 *
 */
public class Page {
	
	//4.总记录数
	private long count;
	//5.分页数据
	private List<Map<String, Object>> data;
	//分页必须五要素
	//1.数据库索引
	private int index;
	//7.[可选]是否有下一页
	private boolean next;

	//3.总页面数
	private int pageSize;
	//6.[可选]是否有上一页
	private boolean previous;
	//2.每页记录数据
	private int size;
	
	public Page(int index, int size, long count, List<Map<String, Object>> data) {
		
		this.index = index;
		this.size = size;
		this.count = count;
		this.data = data;
		//计算总页数
		//总页数=总记录数/每页记录数据 
		//注意：不能整除，需要加1
		if (count%size!=0) {
			this.pageSize=(int)count/size+1;
		}else{
			this.pageSize=(int)count/size;
		}
		
	}
	public long getCount() {
		return count;
	}
	public List<Map<String, Object>> getData() {
		return data;
	}
	public int getIndex() {
		return index;
	}
	public int getPageSize() {
		return pageSize;
	}
	public int getSize() {
		return size;
	}
	public boolean isNext() {
		//判断是否有下一页，小于总页数-1. 
		//问题：为什么需要减1.
		//答：因为数据库的索引是从0开始的，而页面数的计算是从1开始的
		if (index< this.pageSize-1) {
			next=true;
		}else{
			next=false;
		}
		
		return next;
	}
	public boolean isPrevious() {
		//判断是否有上一页：当前页面大于1
		if(index>0){
			previous= true;
		}else{
			previous= false;
		}
		
		return previous;
	}
	public void setCount(long count) {
		this.count = count;
	}
	public void setData(List<Map<String, Object>> data) {
		this.data = data;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public void setSize(int size) {
		this.size = size;
	}
	
	

}
